#!/bin/sh
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/sys_check.sh"
export CURRENT_APP_PATH="${LMD_APPS_DIR}/n8n"
echo 'App Dir: '${CURRENT_APP_PATH}

source "$LMD_BASE_INSTALL_SCRIPT_DIR/apps/n8n/env"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/alias_node.sh"

if [ -d "$CURRENT_APP_PATH" ]; then
  echo "App Dir: "$CURRENT_APP_PATH
else
  echo "Error, App Dir dose not exist, please retry. "$CURRENT_APP_PATH
  exit 1
fi

cd "$CURRENT_APP_PATH"

node -v

if [ -n "$GRADIO_SERVER_PORT" ]; then
  export N8N_PORT=$GRADIO_SERVER_PORT
fi

export N8N_USER_FOLDER="$CURRENT_APP_PATH"

npm run start

